use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
struct SerdeObject {
    #[serde(skip_serializing_if = "Option::is_none")]
    topic: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    topics: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    clientid: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    payload: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    encoding: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    qos: Option<u8>,
}

#[cfg(test)]
mod serde_test {
    use crate::serde::SerdeObject;

    #[tokio::test]
    async fn test_serde() {
        let ser_str = serde_json::to_string(&SerdeObject::default()).unwrap();
        eprintln!("ser str :{}", &ser_str);

        let der_obj = serde_json::from_str::<SerdeObject>(&ser_str).unwrap();

        eprintln!("der obj:{:#?}", &der_obj);
    }
}
